<?php

    define("HTTP_SERVER", "http://localhost/gpa_demo/");
    define("IMAGE_URL", HTTP_SERVER . "images/");
    define("CSS_URL", HTTP_SERVER . "css/");
    define("JS_URL", HTTP_SERVER . "js/");
    define("ROOT_PATH", dirname(__FILE__) . "/");
    define("IMAGE_PATH", ROOT_PATH . "/images/");
    define("CSS_PATH", ROOT_PATH . "/css/");
    define("JS_PATH", ROOT_PATH . "/js/");
    define("THUMBNAIL_PATH", IMAGE_PATH . "thumbs/");
    define("MYSQL_HOST", "localhost");
    define("MYSQL_USER", "root");
    define("MYSQL_PASS", "");
    define("MYSQL_DB", "gpa_new");
    define("TABLE_PREFIX", "gpa_");

    if(count($_POST)) {
        $referrer = parse_url(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : HTTP_SERVER);
        $host = parse_url(HTTP_SERVER);
        $reg = '|^'.preg_quote($host['scheme']).'://[a-zA-Z0-9\.]*'.preg_quote($host['host']).'/|i';

        if(!preg_match($reg, $referrer['scheme'].'://'.$referrer['host'].'/')) {
            die("sorry, but you're trying to post from another host. nice try!");
        }
    }

    ini_set("register_globals", "Off");
    ini_set("magic_quotes_gpc", "Off");
    ini_set("short_open_tag", "Off");

    include_once 'image.php';
    include_once 'mail.php';
    include_once 'database.php';
    $db = Database::initialize(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, TABLE_PREFIX);

    function pwd_gen() {
        $pwd="";
        $args = func_get_args();
        for($i=0,$j=count($args);$i<$j;$i++) {
            $pwd = crypt($pwd, $args[$i].$i);
        }
        return hash("sha256", $pwd);
    }

    function escape($str) {
        global $db;
        return $db->escape($str);
    }

    session_start();

    $CONFIG = array();
    $c = $db->query("SELECT * FROM #_settings")->rows;

    foreach($c as $d) {
        $CONFIG[$d['name']] = $d['value'];
    }

    unset($c);

?>